﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using YSC_Backstage_Web.RestClient;
using YSC_Core.BLL.Domain.BackstageModels;
using YSC_OpenPlatform_API.Entity;
using YSC_Services.BLL.Services.Interfaces;

namespace YSC_Backstage_Web.Controllers
{
    /// <summary>
    /// 鱼种管理
    /// </summary>   
    public class FishSpeciesController : Controller
    {
        private readonly IBasisBackstageServices _pro;
        public FishSpeciesController(IBasisBackstageServices pro)
        {
            _pro = pro;
        }

        /// <summary>
        /// 鱼种列表
        /// </summary>
        /// <returns></returns> 
       
        public IActionResult Index() { return View(); }

        /// <summary>
        /// 鱼种新增
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 鱼种列表(媒体)
        /// </summary>
        /// <returns></returns>
        public IActionResult AppList()
        {
            return View();
        }

        /// <summary>
        /// 鱼种修改
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public IActionResult Edit(string Id)
        {
            var aa = _pro.GetFishSpecies(Id);

            var json = JsonConvert.SerializeObject(aa.Result);
            JObject obj = JObject.Parse(json);
            FishSpecies entity = JsonConvert.DeserializeObject<FishSpecies>(obj["Data"].ToString());

            return View(entity);
        }


        public IActionResult MediaEdit(string Id)
        {
            var aa = _pro.GetFishSpecies(Id);

            var json = JsonConvert.SerializeObject(aa.Result);
            JObject obj = JObject.Parse(json);
            FishSpecies entity = JsonConvert.DeserializeObject<FishSpecies>(obj["Data"].ToString());

            return View(entity);
        }


        /// <summary>
        /// 鱼种列表
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public JsonResult GetList(int limit, int page, string keyword)
        {
            var result = _pro.GetFishSpeciesAll(page, limit, 0, keyword);
            return Json(result);
        }

        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult ImageUpload(string name, string id)
        {
            ViewData["Name"] = name;
            ViewData["Id"] = id;
            return View();
        }


        /// <summary>
        /// 鱼种列表(媒体)
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="sasearch"></param>
        /// <returns></returns>
        public JsonResult GetFishSpeciesAppAll(int index, int size, string sasearch)
        {
            var ret = _pro.GetFishSpeciesAppAll(index, size, sasearch);
            return Json(ret);
        }


        /// <summary>
        /// 鱼种基本信息统一更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AddMediaFishSpecies([FromBody] FishSpeciesModel paramete)
        {
            
           // FishSpeciesModel entity = JsonConvert.DeserializeObject<FishSpeciesModel>(paramete.ToString());
            var result = _pro.AddMediaFishSpecies(paramete);
            return Json(result);
        }

        /// <summary>
        /// 鱼种新增
        /// </summary>
        /// <param name="paramete"></param>
        /// <returns></returns>
        public JsonResult AddEditSubmit(string paramete)
        {
            FishSpeciesModel entity = JsonConvert.DeserializeObject<FishSpeciesModel>(paramete);
            var result = _pro.AddUpdateFishSpecies(entity);
            return Json(result);
        }

        /// <summary>
        /// 鱼种删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public JsonResult DelSubmit(string Id)
        {
            var result = _pro.DelectFishSpecies(Id);
            return Json(result);
        }

    }
}